//
//  CMLoginParser.m
//  CreditManger
//
//  Created by chaiyanan on 15/11/5.
//  Copyright © 2015年 jinxin. All rights reserved.
//

#import "CMLoginParser.h"
#import "CMLoginUserInfo.h"

@implementation CMLoginParser

-(ParserResult*)parseResponseDictionary:(NSDictionary *)responseDictionary
{
    LLog(@"responseDictionary:%@",responseDictionary);
    ParserResult* result=[[ParserResult alloc]init];
    NSNumber* codeObject=[responseDictionary objectForKey:Key_Code];
    if (codeObject)
    {
        NSInteger code = [codeObject integerValue];
        result.code = code;
        result.message = [responseDictionary objectForKey:Key_Msg];
        if (code == 0)
        {
            NSDictionary *dataDict = [responseDictionary objectForKey:Key_Data];
            if (dataDict&&[dataDict isKindOfClass:[NSDictionary class]])
            {
                CMLoginUserInfo *info = [[CMLoginUserInfo alloc]init];
                info.uid = [DataTypeTranslate numberToString:dataDict[Key_uid]];
                info.token = [DataTypeTranslate stringToString:dataDict[Key_token]];
                info.mobile = [DataTypeTranslate numberToString:dataDict[Key_mobile]];
                info.username = [DataTypeTranslate stringToString:dataDict[Key_username]];
                info.cardno = [DataTypeTranslate stringToString:dataDict[Key_cardno]];
                info.headImg = [DataTypeTranslate stringToString:dataDict[Key_headImg]];
                info.identityStatus = [DataTypeTranslate numberToString:dataDict[Key_identityStatus]];
                
                result.result = info;
            }
            else
            {
                result.code=1;
                result.message=@"服务器数据异常";
            }
        }
        
    }
    else
    {
        result.code=1;
        result.message=@"服务器数据异常";
    }
    
    return result;
}

@end
